package com.atguigu.gulimall.order.utils;

import org.springframework.util.Assert;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description
 * @Author lhj
 * @Date 2024/5/2 10:02
 */
public class HttpRequestUtils {

    /**
     * 根据请求上下文对象获取request请求
     * @return request
     */
    public static HttpServletRequest httpServletRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        //请求不能为空
        Assert.notNull(requestAttributes, "The Request Cannot be empty!");
        return requestAttributes.getRequest();
    }
    
}
